﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 自定义泛型集合3
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Persons persons = new Persons();

            Person p = new Person() { Name = "Tim", Age = 34 };
            persons.Add(p);

            p = new Person() { Name = "Jim", Age = 32 };
            persons.Add(p);

            p = new Person() { Name = "Mari", Age = 38 };
            persons.Add(p);

            persons.Reverse();// 反序

            foreach (var item in persons)
            {
                Console.WriteLine((item as Person).Name);
            }

            Console.ReadKey();
        }
    }

    public class Person:IComparable<Person>
    {
        protected int age;
        public int Age { get { return age; } set { age = value; } }
        protected string name;
        public string Name { get { return name; } set { name = value; } }

        public Person()
        {

        }

        public int CompareTo(Person other)
        {
            if(this.Age > 0 && other.Age > 0)
            {
                return this.Age.CompareTo(other.Age);
            }
            else
            {
                return 0;
            }
        }
    }

    public class Persons : List<Person>
    {


    }
}
